package com.ck567.springbootnettyprotobufjava.utils;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @description: 操作类型
 */
@Getter
@AllArgsConstructor
public enum OptionType {

    HeartBeatsReq((short) 1),
    HeartBeatsResp((short) 2),
    LoginReq((short) 3),
    LoginResp((short) 4),
    LogoutSync((short) 6),
    GroupChatReq((short) 7),
    GroupChatSync((short) 8),
    SceneSync((short) 10),
    ExpressionSync((short) 12),
    HistoryMsgReq((short) 13),
    HistoryMsgResp((short) 14),
    GiftSync((short) 16),
    JoinGroupReq((short) 17),
    JoinGroupResp((short) 18),
    ;
    /**
     * 操作类型
     */
    private final short type;

    /**
     * @param type 消息类型
     * @return 操作类型
     * @description: 根据消息类型获取操作类型
     */
    public static OptionType getType(short type) throws Exception {
        switch (type) {
            case 1:
                return HeartBeatsReq;
            case 2:
                return HeartBeatsResp;
            case 3:
                return LoginReq;
            case 4:
                return LoginResp;
            case 6:
                return LogoutSync;
            case 7:
                return GroupChatReq;
            case 8:
                return GroupChatSync;
            case 10:
                return SceneSync;
            case 12:
                return ExpressionSync;
            case 13:
                return HistoryMsgReq;
            case 14:
                return HistoryMsgResp;
            case 16:
                return GiftSync;
            case 17:
                return JoinGroupReq;
            case 18:
                return JoinGroupResp;
        }
        throw new Exception(String.format("[type]:%d,无此操作了类型", type));
    }
}
